package com.sdx.common.utils;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

import java.text.SimpleDateFormat;

/**
 * @ClassName JacksonUtils
 * @Description: 基于Jackson的工具类
 * @author: tanbaocai
 * @date: 2018/7/27 17:33
 */
public class JacksonUtils {
	public static final String DF_SHORT1 = "yyyy-MM-dd";
	public static final String DF_SHORT2 = "yyyyMMdd";
	public static final String DF1 = "yyyy-MM-dd HH:mm:ss";
	public static final String DF2 = "yyyyMMddHHmmss";
	public static String toJsonString(Object obj,String dfStr) throws JsonProcessingException {
		ObjectMapper mapper = new ObjectMapper();
		mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
		//SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		SimpleDateFormat df = new SimpleDateFormat(dfStr);
		mapper.setDateFormat(df);
		return mapper.writeValueAsString(obj);
	}
}
